package Demo1;

import java.io.Serializable;
import java.util.Objects;

/**
 * 一个普通的java Bean
 * java:咖啡
 * Bean是豆子
 *一个普通的javaBean有如下规范:
 *  午餐有参构造方法
 *  属性私有化
 *  提供get和set方法
 */
public class User implements Serializable {
    private  String id;
    private String name;

    public User(String id, String name) {
        this.id = id;
        this.name = name;
    }

    // id和name一样就说明是同一个人
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof User user)) return false;
        return Objects.equals(id, user.id) && Objects.equals(name, user.name);
    }



    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                '}';
    }

    public User() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
